/**
 * 校验合计需还必须是0~2位小数的正实数
 * @param {*} rule 规则
 * @param {number} value 合计需还
 * @param {Function} callback 回调函数
 */
const validateFloatNum = name => (rule, value, callback) => {
    const reg = /^[0-9]+(\.[0-9]{0,2})?$/;

    if (value && !reg.test(value)) {
        return callback(new Error(name + '应为0-2位小数的正实数'));
    }
    callback();
};

export default function getRules(options) {
    const RULES = {
        name: [{required: true, message: '名称必填项', trigger: ['change', 'blur']}],
        contact: [{required: true, message: '联系人必填项', trigger: ['change', 'blur']}],
        phone: [{required: true, message: '联系电话必填项', trigger: ['change', 'blur']}],
        outStart: [{validator: validateFloatNum('期初应付'), trigger: ['change', 'blur']}],
        outEnd: [{validator: validateFloatNum('期末应付'), trigger: ['change', 'blur']}],
        // address: [{required: true, message: '地址必填项', trigger: ['change', 'blur']}]
        // remark: [{required: false, message: '请填角色备注', trigger: ['change', 'blur']}]
        ...options
    };
    return RULES;
}
